package com.createdevelopment.house.action;

import java.io.File;
import java.util.List;

import com.createdevelopment.house.entity.House;
import com.createdevelopment.house.entity.Picture;
import com.createdevelopment.house.entity.PublicFacility;
import com.createdevelopment.house.service.house.HouseService;
import com.createdevelopment.house.service.picture.PictureService;
import com.createdevelopment.house.service.publicfacility.PublicFacilityService;

@SuppressWarnings("serial")
public class HouseAction extends BaseAction {
	List<House> houses;
	HouseService houseService;
	PictureService pictureService;
	House house;
    private File logo;
	private String logoFileName;
    private File over_view;
    private String over_viewContentType;
	private String over_viewFileName;
	private String realPathString;
	private List<Picture> picturesOfHouse;
	private String houseId;
	private List<PublicFacility> notRelatedPulbicFacilities;
	private PublicFacilityService publicFacilityService;
    private String[] selectedPublicFacilities;
	
	
	public String showAllHouses(){
		houses=houseService.getAllHouses();
		return SUCCESS;
	}
	
	public String showAddHouse(){
		return SUCCESS;
	}
		
    public String obtainHouses(){
    	return SUCCESS;
    }
    
    public String saveHouse(){
    	
    	realPathString=this.getRequest().getRealPath("/");
    	if(logo!=null){
    		Picture logoPicture=pictureService.savePicture(null, logo, logoFileName, realPathString);
    		house.setLogo(logoPicture);
    	}
    	
    	if(over_view!=null){
	    	Picture over_viewPicture=pictureService.savePicture(null, over_view, over_viewFileName, realPathString);
	    	house.setOver_view(over_viewPicture);
    	}
    	houseService.saveHouse(house);
    	return SUCCESS;
    }
    
    public String loadNearbyPublicFacilities(){
    	house=houseService.getASpecifiedHouse(houseId);
    	notRelatedPulbicFacilities=publicFacilityService.findNotRelatedPublicFacilities(house);
    	return SUCCESS;
    }
    
    public String saveRelatedPublicFacilities(){
    	houseService.saveRelatedPublicFacilities(houseId,selectedPublicFacilities);
    	return SUCCESS;
    }
    /*
     * set and get methods start from here
     */
	public void setHouses(List<House> houses) {
		this.houses = houses;
	}
	
	public List<House> getHouses(){
		return houses;
	}
	public HouseService getHouseService() {
		return houseService;
	}
	public void setHouseService(HouseService houseService) {
		this.houseService = houseService;
	}

	public House getHouse() {
		return house;
	}

	public void setHouse(House house) {
		this.house = house;
	}

	public File getLogo() {
		return logo;
	}

	public void setLogo(File logo) {
		this.logo = logo;
	}

	public String getLogoFileName() {
		return logoFileName;
	}

	public void setLogoFileName(String logoFileName) {
		this.logoFileName = logoFileName;
	}

	public File getOver_view() {
		return over_view;
	}

	public void setOver_view(File over_view) {
		this.over_view = over_view;
	}

	public PictureService getPictureService() {
		return pictureService;
	}

	public void setPictureService(PictureService pictureService) {
		this.pictureService = pictureService;
	}

	public String getOver_viewContentType() {
		return over_viewContentType;
	}

	public void setOver_viewContentType(String over_viewContentType) {
		this.over_viewContentType = over_viewContentType;
	}

	public String getover_viewFileName() {
		return over_viewFileName;
	}

	public void setover_viewFileName(String lover_viewFileName) {
		this.over_viewFileName = lover_viewFileName;
	}

	public String getOver_viewFileName() {
		return over_viewFileName;
	}

	public void setOver_viewFileName(String over_viewFileName) {
		this.over_viewFileName = over_viewFileName;
	}

	public List<Picture> getPicturesOfHouse() {
		return picturesOfHouse;
	}

	public void setPicturesOfHouse(List<Picture> picturesOfHouse) {
		this.picturesOfHouse = picturesOfHouse;
	}

	public String getHouseId() {
		return houseId;
	}

	public void setHouseId(String houseId) {
		this.houseId = houseId;
	}

	public String getRealPathString() {
		return realPathString;
	}

	public void setRealPathString(String realPathString) {
		this.realPathString = realPathString;
	}

	public List<PublicFacility> getNotRelatedPulbicFacilities() {
		return notRelatedPulbicFacilities;
	}

	public void setNotRelatedPulbicFacilities(
			List<PublicFacility> notRelatedPulbicFacilities) {
		this.notRelatedPulbicFacilities = notRelatedPulbicFacilities;
	}

	public PublicFacilityService getPublicFacilityService() {
		return publicFacilityService;
	}

	public void setPublicFacilityService(PublicFacilityService publicFacilityService) {
		this.publicFacilityService = publicFacilityService;
	}

	public String[] getSelectedPublicFacilities() {
		return selectedPublicFacilities;
	}

	public void setSelectedPublicFacilities(String[] selectedPublicFacilities) {
		this.selectedPublicFacilities = selectedPublicFacilities;
	}
	
	
    
}
